/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network.packets;

import datamodel.Order2;
import utils.Utils;

/**
 *
 * @author Kvest
 */
public class OrderResponce2 extends OrderResponce
{
    public OrderResponce2(int id)
    {
        super(id);
    }
    
    public OrderResponce2(byte[] data)
    {
        super(ORDER_RESPONCE2);
        order = new Order2(-1);

        parse(data);
    }

    public void createOrder()
    {
        order = new Order2(-1);
    }

    protected void parse(byte[] data)
    {
        int offset = 0;

        //Пропускаем название пакета
        byte[] buffer4 = new byte[4];
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length + Utils.byteToInt(buffer4);
        
        parse(data, offset);
    }
    
    public int parse(byte[] data, int offset)
    {
        byte[] buffer4 = new byte[4];  
        
        //agentPay
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length + Utils.byteToInt(buffer4);
        
        //features
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        int count = Math.max(Utils.byteToInt(buffer4), 0);
        
        for (int j = 0; j < count; ++j)
        {
            System.arraycopy(data, offset, buffer4, 0, buffer4.length);
            offset += buffer4.length +  Utils.byteToInt(buffer4);
        }

        //agentName
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length +  Utils.byteToInt(buffer4);

        //dispPhone
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length +  Utils.byteToInt(buffer4);

        //ColorClass
        offset += buffer4.length;

        //autoClass;
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length +  Utils.byteToInt(buffer4);

        //searchType

        //clientName
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length +  Utils.byteToInt(buffer4);

        //receiptMustHave;
        offset++;
        
        buffer4 = null;
        
        return super.parse(data, offset);
    }
}
